<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=9"/>
<meta name="generator" content="Doxygen 1.8.13"/>
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<title>OrangeCNC - ARISC firmware documentation: mod_msg.c</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="dynsections.js"></script>
<link href="navtree.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="resize.js"></script>
<script type="text/javascript" src="navtreedata.js"></script>
<script type="text/javascript" src="navtree.js"></script>
<script type="text/javascript">
  $(document).ready(initResizable);
</script>
<link href="search/search.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="search/searchdata.js"></script>
<script type="text/javascript" src="search/search.js"></script>
<link href="doxygen.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
<div id="titlearea">
<table cellspacing="0" cellpadding="0">
 <tbody>
 <tr style="height: 56px;">
  <td id="projectalign" style="padding-left: 0.5em;">
   <div id="projectname">OrangeCNC - ARISC firmware documentation
   </div>
  </td>
 </tr>
 </tbody>
</table>
</div>
<!-- end header part -->
<!-- Generated by Doxygen 1.8.13 -->
<script type="text/javascript">
var searchBox = new SearchBox("searchBox", "search",false,'Search');
</script>
<script type="text/javascript" src="menudata.js"></script>
<script type="text/javascript" src="menu.js"></script>
<script type="text/javascript">
$(function() {
  initMenu('',true,false,'search.php','Search');
  $(document).ready(function() { init_search(); });
});
</script>
<div id="main-nav"></div>
</div><!-- top -->
<div id="side-nav" class="ui-resizable side-nav-resizable">
  <div id="nav-tree">
    <div id="nav-tree-contents">
      <div id="nav-sync" class="sync"></div>
    </div>
  </div>
  <div id="splitbar" style="-moz-user-select:none;" 
       class="ui-resizable-handle">
  </div>
</div>
<script type="text/javascript">
$(document).ready(function(){initNavTree('mod_msg_8c-example.html','');});
</script>
<div id="doc-content">
<!-- window showing the filter options -->
<div id="MSearchSelectWindow"
     onmouseover="return searchBox.OnSearchSelectShow()"
     onmouseout="return searchBox.OnSearchSelectHide()"
     onkeydown="return searchBox.OnSearchSelectKey(event)">
</div>

<!-- iframe showing the search results (closed by default) -->
<div id="MSearchResultsWindow">
<iframe src="javascript:void(0)" frameborder="0" 
        name="MSearchResults" id="MSearchResults">
</iframe>
</div>

<div class="header">
  <div class="headertitle">
<div class="title">mod_msg.c</div>  </div>
</div><!--header-->
<div class="contents">
<p><b>Usage example 1</b>: sending mirror messages back to the ARM cpu with message count limit of 100</p>
<div class="fragment"><div class="line"><span class="preprocessor">#include &lt;stdint.h&gt;</span></div><div class="line"><span class="preprocessor">#include &quot;<a class="code" href="mod__msg_8h.html">mod_msg.h</a>&quot;</span></div><div class="line"></div><div class="line"><span class="keywordtype">int</span> msg_counter = 0; <span class="comment">// messages counter</span></div><div class="line"></div><div class="line"><span class="comment">// callback for the `message received` event</span></div><div class="line">int32_t <span class="keyword">volatile</span> msg_received(uint8_t type, uint8_t * msg, uint8_t length)</div><div class="line">{</div><div class="line">    <span class="comment">// send mirror message</span></div><div class="line">    <a name="a0"></a><a class="code" href="mod__msg_8c.html#aad162e5eb1e3fb9806dc50c01ecb7d70">msg_send</a>(type, msg, length);</div><div class="line">    <span class="comment">// increase messages count</span></div><div class="line">    msg_counter++;</div><div class="line">    <span class="comment">// abort messages receiving after 100 incoming messages</span></div><div class="line">    <span class="keywordflow">if</span> ( msg_counter &gt;= 100 ) <a name="a1"></a><a class="code" href="mod__msg_8c.html#a99224966c8fcbf2162a8949640e99684">msg_recv_callback_remove</a>(type);</div><div class="line">    <span class="comment">// normal exit</span></div><div class="line">    <span class="keywordflow">return</span> 0;</div><div class="line">}</div><div class="line"></div><div class="line"><span class="keywordtype">int</span> <a name="a2"></a><a class="code" href="main_8c.html#a840291bc02cba5474a4cb46a9b9566fe">main</a>(<span class="keywordtype">void</span>)</div><div class="line">{</div><div class="line">    <span class="comment">// module init</span></div><div class="line">    <a name="a3"></a><a class="code" href="mod__msg_8c.html#a577ee695bade6a55efa4c5a7d9866a74">msg_module_init</a>();</div><div class="line"></div><div class="line">    <span class="comment">// assign incoming messages callback for the message type 123</span></div><div class="line">    <a name="a4"></a><a class="code" href="mod__msg_8c.html#a51c02043fa74dd30c73670ca0c066727">msg_recv_callback_add</a>(123, (<a name="a5"></a><a class="code" href="mod__msg_8h.html#a374ff7872dc0e70bbc8b4c5273b2c703">msg_recv_func_t</a>) &amp;msg_received);</div><div class="line"></div><div class="line">    <span class="comment">// main loop</span></div><div class="line">    <span class="keywordflow">for</span>(;;)</div><div class="line">    {</div><div class="line">        <span class="comment">// real reading/sending of a messages</span></div><div class="line">        <a name="a6"></a><a class="code" href="mod__msg_8c.html#ac7611d9252e22be0140ad3beb46eb8a2">msg_module_base_thread</a>();</div><div class="line">    }</div><div class="line"></div><div class="line">    <span class="keywordflow">return</span> 0;</div><div class="line">}</div></div><!-- fragment --><div class="fragment"></div><!-- fragment --> </div><!-- contents -->
</div><!-- doc-content -->
<!-- start footer part -->
<div id="nav-path" class="navpath"><!-- id is needed for treeview function! -->
  <ul>
    <li class="footer">Generated by
    <a href="http://www.doxygen.org/index.html">
    <img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.8.13 </li>
  </ul>
</div>
</body>
</html>
